import { Component } from "react";

export default class Table extends Component {
    constructor() {
        super()
        this.state = {
            // user: "",
            // age: "",
            // flag: true,
            // editId: ""
        }
    }
    del = (id) => {
        this.props.del(id)
    }
    edit = (id) => {
        this.props.edit(id)
    }
    render() {
        return (
            <table border={1}>
                <thead>
                    <tr>
                        <th>名字</th>
                        <th>年龄</th>
                        <th>操作</th>
                    </tr>

                </thead>
                <tbody>
                    {
                        this.props.list.map(v => {
                            return (<tr key={v.id}>
                                <td>{v.user}</td>
                                <td>{v.age}</td>
                                <td><button onClick={() => this.del(v.id)}>删除</button></td>
                                <td><button onClick={() => this.edit(v.id)}>编辑</button></td>
                            </tr>)
                        })
                    }
                </tbody>
            </table>
        )
    }
}




















